﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GeneticAlgorithm.Demo.Common.Function.UnaryFunction
{
    [DisplayText(FunctionType.UnaryFunction1, "y=xsin(10πx)+2")]
    internal class UnaryFunction1 : IUnaryFunction
    {
        public UnaryFunction1()
        {
            this.Range = (-1, 2);
            this.Solve = SolveType.Max;
            this.Accuracy = 6;
        }
        public (double lower, double upper) Range { get; set; }
        public byte Accuracy { get; set; }
        public SolveType Solve { get; set; }
        public int GeneMinLength => (int)Math.Ceiling(Math.Log2((Range.upper - Range.lower) * Math.Pow(10, Accuracy)));

        public double Func(double x)
        {
            // y=xsin(10πx)+2
            return x * Math.Sin(10 * Math.PI * x) + 2d;
        }
    }
}
